--- Demonstration of terminal input/output
module examples.SimpleIO where

import Test.QuickCheck

--- The 'main' function will be called by the runtime when you run the 'SimpleIO' class.
--- It will get passed the list of command line arguments, but we ignore them here.
main _ = forever interaction 
            `catch` eof
            `finally` println "See you again."
    where
        interaction = do
            reply <- prompt "Enter integer number: "
            case reply.integer of
                Left _  -> println ("`" ++ reply ++ "` is not an integer.")
                Right n -> println (show n ++ " is " 
                                    ++ (if even n then "even" else "odd")
                                    ++ ".")
        prompt s = do
            stdout.print s
            stdout.flush
            getLine
        eof :: EOFException -> IO ()
        eof _ = print "Good bye. "

{-- 
    The property 'p_test' checks the claim that
    every integral number must be either odd or even.
-}             
p_test = property $ \(n::Integer) -> odd n ^^ even n